<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:19
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-25 17:58:51
 * ------------------------------------------------ *
 * 店铺管理                                         *
 * ------------------------------------------------ */

namespace Admin\Controller;
class ShopsController extends CommonController {

	public function index(){
		if(IS_AJAX){
			switch(I('ajax')){
				//地区列表
				case "getRegion":
					$r=M('region');
					$rs = $r->where('pid='.(int)I('id'))->select();
					$this->ajaxReturn($rs);
					break;
				//检查用户
				case "checkUser":				
					$user=D('users')->where('loginName="'.I('loginName').'"')->find();				
					$this->ajaxReturn(!$user);
					break;
				//检查店铺
				case "checkShop":				
					$user=D('shops')->where('shopName="'.I('shopName').'"')->find();				
					$this->ajaxReturn(!$user);
					break;
				//检查手机
				case "checkPhone":				
					$user=D('users')->where('userPhone="'.I('userPhone').'"')->find();				
					$this->ajaxReturn(!$user);
					break;
				//拒绝
				case "startShops":					
			 		$status = D('Shops')->startShops();
			 		$this->ajaxReturn($status);
					break;	
				//拒绝
				case "stopShops":					
			 		$status = D('Shops')->stopShops();
			 		$this->ajaxReturn($status);
					break;	
				//删除
				case "delShops":
					$status = D('Shops')->delShops();
					$this->ajaxReturn($status);
					break;				
				//列表
				default:					
			 		$result = D('Shops')->getShops();
			 		$output['data'] = $result;
			 		$this->ajaxReturn($output);
			}
		}
		if(I('noAjax')=="editShops"){
			
			if((int)I('shopId',0)>0){
				$m = D('Shops')->editShops();
				if($m){	
									
					echo "<script>parent.callback('店铺修改成功！',1)</script>";
					return;
				}		
				echo "<script>parent.callback('店铺修改失败！',0)</script>";
				return;
			}
			$m = D('Shops')->addShops();

			if($m){	
				//echo "<script>parent.callback('".$m."',0)</script>";				
				echo "<script>parent.callback('店铺添加成功！',1)</script>";
				return;
			}		
			echo "<script>parent.callback('店铺添加失败！',0)</script>";
			return;

		}

		$this->display();
	}


	public function pend(){
		if(IS_AJAX){

			$result = D('Shops')->getShopsPendding();
			$output['data'] = $result;
			$this->ajaxReturn($output);
		}

		$this->display();
	}

	public function edit(){
		$catName1 = M('goods_cats')->where("catFlag=1 and parentId=0")->field('catId,catName')->select();
		$banks = M('banks')->where("bankFlag=1")->select();
		if((int)I('shopId',0)>0){
			$shops = M('shops')->where('shopId='.(int)I('shopId'))->find();
			$users = M('users')->where('userId='.$shops['userId'])->find();
			$this->assign('shops',$shops);
			$this->assign('users',$users);
		}
		$this->assign('catName1',$catName1);
		$this->assign('banks',$banks);
		
		$this->display();
	}
}